package top.yxqz.ck;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLDecoder;

/**
 * @author Mr.余
 * @date 2022/11/23
 * @package top.yxqz.ck
 * 得到Cookie
 * HttpServletRequest 对象
 */
@WebServlet("/demo2")
public class CookieDemo2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie[] cookies = request.getCookies();
        //        String value = URLDecoder.decode(cookie.getValue(), "UTF-8");
        for (Cookie ck: cookies
             ) {
            String ckName = URLDecoder.decode(ck.getName(), "UTF-8");
            String ckValue = URLDecoder.decode(ck.getValue(), "UTF-8");
            System.out.println("ckName:"+ckName+"\tckValue:"+ckValue);
//            if ("student".equals(ck.getName())){
//                System.out.println("我想要的东西："+ck.getValue());
//            }
        }
    }
}
